-- @owner: wan005
-- @date: 2024/10/8
-- @testpoint: pipelined函数中入参类型不匹配，部分合理报错
-- @modify: modified by zhangbingliang at 2025.01,优化用例适配代码变更
--pre1:切换A库执行
@conn PrimaryDbAmode;

--step1:创建数据类型;expect:成功
create or replace type type_0022 as (c1 integer, c2 tinyint);
create or replace type tb_type_0022 as table of type_0022;
create or replace type array_type_0022 as varray(10) of date;

--step2:创建管道函数返回值类型不匹配;expect:失败
create or replace function func_pipelined_022(count in number)
returns tb_type_0022 pipelined
as $$
declare result type_0022;
begin
for i in 1 .. count loop
result.c1 = 'sdfsc';
result.c2 = 'sdfsadgw';
pipe row(result);
end loop;
return;
end;
$$ language plpgsql;
/

select func_pipelined_022(1);
select * from func_pipelined_022(1);

create or replace function func_pipelined_0022_1(count in number)
returns array_type_0022 pipelined
as $$
declare result integer;
begin
for i in 1 .. count loop
result := array['sdfs@3', -2, 0, -0, 6, 7];
pipe row(result[i]);
end loop;
return;
end;
$$ language plpgsql;
/

select func_pipelined_022_1(1);
select * from func_pipelined_022_1(1);

--step6:清理环境;expect:成功
drop type if exists array_type_0022 cascade;
drop type if exists tb_type_0022 cascade;
drop type if exists type_0022 cascade;
drop function if exists func_pipelined_022;
drop function if exists func_pipelined_022_1;
